<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Configuration_model Class 
 * 
 * @author vu.nguyen
 */
class Configuration_model extends DataMapper {

    var $model = 'configuration_model';
    var $table = 'news';
    
    // --------------------------------------------------------------------
    var $validation = array(
        'title' => array(
            'rules' => array('required','trim', 'max_length' => 100)
        )
    );
    // --------------------------------------------------------------------
    /**
     * Default order in query select 
     */
    var $default_order_by = array('id');

    // --------------------------------------------------------------------
    /**
     * string value of object
     * 
     * @access private
     * @param null
     * @return string 
     */
    function __toString() {
        return empty($this->title) ? '---empty---' : $this->title;
    }

    // --------------------------------------------------------------------
    /**
     * array of field for auto generate form
     * 
     * @access public
     * @param int
     * @return array 
     */
    function form_fields() {
        return array(
            // id -> Hidden
            'title' => array(
                'class' => 'field text full'
            )
        );
    }

    // --------------------------------------------------------------------
    /**
     * array of field for submit form
     * 
     * @access public
     * @param null
     * @return array 
     */
    function form_post() {
        return array(
            // id -> Hidden
            
            'title'
        );
    }
     /**
     * Array metadata for generate jquery grid
     * show data
     * 
     * @access public
     * @param null
     * @return array 
     */
    function jqgrid_metadata() {
        return array(
            'names' => array(
                'id',
                $this->localize_label('title')
            ),
            'model' => array(
                array('name' => 'id', 'hidden' => TRUE, 'key' => TRUE,
                    'editrules' => array('edithidden' => TRUE)
                ),
                array('name' => 'title', 'width' => '100',
                    'searchoptions' => array(
                        'sopt' => array('cn', 'nc', 'eq', 'bw', 'bn', 'ew', 'en')
                    )
                )
            )
        );
    }
    // --------------------------------------------------------------------
    /**
     * check edit object permit
     * 
     * @access public
     * @param obj
     * @return bool
     */
    function check_edit($user = FALSE) {
        $group = new Group_model();
        $group->select('id,title');
        $group->where('id', $user->group->id);
        $group->get(1);
        $check = false;
        foreach ($group->role->get_iterated() as $role) {
            if ($role->keyword == 'configuration')
                $check = TRUE;
        }
        return $check;
    }
    // -----------------------------------------------------------
    /**
     * Check create object permit,
     * check user before create form add menu
     * @access public
     * @param object
     * @return boolean
     * 
     */    
    function check_create($user = FALSE) {
        // check role                           
        $group = new Group_model();
        $group->select('id,title');
        $group->where('id', $user->group->id);
        $group->get(1);
        $check = false;
        foreach ($group->role->get_iterated() as $role) {
            if ($role->keyword == 'configuration')
                $check = TRUE;
        }
        return $check;
    }    
     // -----------------------------------------------------------
    /**
     * Check delete object permit,
     * check user before create form delete menu
     * 
     * @access public
     * @param object
     * @return boolean 
     */
    function check_delete($user = FALSE) {
        // check role                           
        $group = new Group_model;
        $group->select('id,title');
        $group->where('id', $user->group->id);
        $group->get(1);
        $check = false;
        foreach ($group->role->get_iterated() as $role) {
            if ($role->keyword == 'configuration')
                $check = TRUE;
        }
        return $check;
    }
    // --------------------------------------------------------------------
    /**
     * array active of object
     * 
     * @access public
     * @param bool
     * @return array
     */
    function allow_comment_list($zero = FALSE) {
        $allow_comment_list = $this->validation['allow_comment']['values'];
        if ($zero) {
            $allow_comment_list = array_merge(array('' => '--Tất cả--'), $allow_comment_list);
        }
        return $allow_comment_list;
    }
    // --------------------------------------------------------------------
    /**
     * string value of active
     * 
     * @access public
     * @param obj
     * @return bool
     */
    function get_allow_comment() {
        return $this->validation['allow_comment']['values'][$this->allow_comment];
    }
}

/* End of file configuration.php */
/* Location: ./application/models/configuration.php */